package com.sunda.spmscommon.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sunda.spmscommon.entity.SysLogMq;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.ClobTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * MQ系统日志表 Mapper 接口
 * </p>
 *
 * @author Wayne
 * @since 2021-05-27
 */
@Mapper
public interface SysLogMqMapper extends BaseMapper<SysLogMq> {

    @Select("SELECT ROWNUM,\n" +
            "       RE.LOG_AUTO_ID AS \"logAutoId\",\n" +
            "       (CASE WHEN RE.LOG_TYPE = '1' THEN '发送MQ日志'\n" +
            "           WHEN RE.LOG_TYPE = '2' THEN '接收MQ日志'\n" +
            "           WHEN RE.LOG_TYPE = '3' THEN '发送REST日志'\n" +
            "           ELSE '接收REST日志' END ) AS \"logType\",\n" +
            "       RE.REQUEST_INTERFACE AS \"requestInterface\",\n" +
            "       RE.REQUEST_DESC AS \"requestDesc\",\n" +
            "       RE.FUNCTION_ID AS \"functionId\",\n" +
            "       RE.REQUEST_PARAM AS \"requestParam\",\n" +
            "       RE.USER_ID AS \"userId\",\n" +
            "       RE.CREATE_TIME AS \"createTime\",\n" +
            "       RE.REMARKS AS \"remarks\"\n" +
            "FROM (\n" +
            "    SELECT * FROM SYS_LOG_MQ LM \n" +
            "    WHERE 1=1 \n" +
            "       AND LM.LOG_TYPE = #{logType} \n" +
            "    ORDER BY LM.LOG_AUTO_ID DESC) RE\n" +
            "WHERE ROWNUM <= 20 ")
    @Results({
            @Result(column = "requestParam", property = "requestParam", javaType = String.class,
                    jdbcType = JdbcType.CLOB, typeHandler = ClobTypeHandler.class),
            @Result(column = "remarks", property = "remarks", javaType = String.class,
                    jdbcType = JdbcType.CLOB, typeHandler = ClobTypeHandler.class)
    })
    List<Map<String, Object>> getSysLogMq(@Param("logType") String logType);
}
